# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-ca-certs-nss
_pkgname=ca-certs-nss
pkgver=3.89.1
pkgrel=1
pkgdesc="X.509 trust anchors extracted from Mozilla's NSS"
url="https://github.com/mirage/ca-certs-nss"
arch="all !riscv64 !loongarch64" # ocaml
license="ISC"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-mirage-clock-dev
	ocaml-mirage-crypto-dev
	ocaml-x509-dev
	"
makedepends="
	$depends_dev
	dune
	ocaml
	ocaml-astring-dev
	ocaml-bos-dev
	ocaml-cmdliner-dev
	ocaml-logs-dev
	ocaml-fmt-dev
	gmp-dev
	"
checkdepends="ocaml-alcotest-dev"
options="!check"
subpackages="$pkgname-dev $pkgname-tools"
source="$pkgname-$pkgver.tar.bz2::https://github.com/mirage/ca-certs-nss/releases/download/v$pkgver/ca-certs-nss-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

tools() {
	pkgdesc="$pkgdesc (command line utilities)"
	depends=""

	amove usr/bin
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
274d59075585ca13420c2d35082e9d12e1d842620c9b13e2215e0ade8c114d18e85dfe08da24f51dbfe69abccaef14d0ca6968f6073718063a925cdc9986699e  ocaml-ca-certs-nss-3.89.1.tar.bz2
"
